package lambda;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;


/**
 * @author Summerday
 */
public class FunctionInterfaceTest {

    public static void main(String[] args) {
        supplierTest();
    }

    /**
     * 消费型接口, 传入T 无返回值
     */
    public static void consumerTest() {
        Consumer<Integer> consumer = num -> System.out.println(num * num);
        consumer.accept(10);
    }

    /**
     * 供给型接口, 无参数,返回T
     */
    public static void supplierTest() {
        Supplier<Object> supplier = () -> new Object();
        System.out.println(supplier.get());
    }

    /**
     * 断言型 传入参数T ,返回boolean
     */
    public static void predicateTest() {
        Predicate<String> predicate = name -> name.startsWith("summer");
        System.out.println(predicate.test("summerday"));
    }

    /**
     * 函数型接口 传入T 返回R
     */
    public static void functionTest() {
        List<Integer> list = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
        Function<List<Integer>, Integer> function = num -> {
            int res = 0;
            for (int n : list) {
                res += n;
            }
            return res;
        };
        Integer num = function.apply(list);
        System.out.println(num);
    }

    public static void intPredicateTest(){
        IntPredicate isEven = (int i) -> i % 2 == 0;
        boolean b = isEven.test(1000);
        System.out.println(b);
    }


    public static void BinaryOperatorTest(){
        BinaryOperator<Function<Integer, Integer>> compose = (f, g) -> {
            return x -> g.apply(f.apply(x));
        };



    }


}